package com.example.myapplication.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter
import com.example.myapplication.databinding.SplashViewpagerItemBinding

class SplashViewPagerAdapter(val data: Array<Int>) : PagerAdapter() {
    override fun getCount(): Int {
        return data.size
    }

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view == `object`
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val binding = SplashViewpagerItemBinding.inflate(LayoutInflater.from(container.context))
        binding.imageView.setImageResource(data[position])
        binding.radioGroup.check(binding.radioGroup.getChildAt(position).id)
        if (position == data.size - 1) {
            binding.button.visibility = View.VISIBLE
        }
        container.addView(binding.root)
        return binding.root
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeView(`object` as View)
    }
}